/**
 * Created by zhengchuan on 2017/6/5.
 */
console.log('加载js文件')
var indexNur = 0;
var vefJs = true;
var eCode = "";
var interval;
$(document).keyup(function(event) {
    if (event.keyCode == 13) {
        vefJs = false;
        eCode = event.keyCode;

    }
});
// $(document).keypress(function(e) {
//     eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
// });


var app = new Vue({
        el: '#app',
        data: {
            anType: true,
            payType: false,
            barCode: '', //输入的条码
            totalAmt: '0', //总价
            befAmt: '0', //优惠价
            showProdImage: '', //查看的图片
            orderId: '', //当前提交的订单号
            xuLieHao: '0',
            dingShiQiId: '', //定时获取订单状态的定时器Id
            payQrCodeModalId: '', //支付二维码的弹框ID
            changeId: '', //找零的弹框ID
            mobile: '',   //手机号
            productList: [
                /*{
                 prodName: 'hehe', //店家备注名
                 quantity: '2',
                 seqId:"", //单条记录主键
                 barCode:"",
                 imageUrl:'',
                 address : '',
                 cstPrice : '', //进价
                 rtlPrice : '12', //零售价格
                 mfrName : '', //生产厂商
                 productName : '',//条码总局返回的商品名称
                 spec : '', //规格
                 sales : '', //销量
                 stock : '', //库存
                 }*/
            ],
            user: {
                userId: $("#user_id").val(),
                shopId: $("#shop_id").val()
            },
            gatheringWay: [],
            totalPrices: ''
        },
        watch: {
            // 如果 barCode 发生改变，这个函数就会运行
            barCode: function (newBarCode) {
                // //console.log(newBarCode)
                this.getProductInfo()
            },
            productList: function () {
                var tempAmt = 0;
                anCode = 1;
                for (idx in this.productList) {
                    var product = this.productList[idx];
                    console.log('====条数据====>')
                    var rtlPrice = product.rtlPrice;
                    tempAmt = this.addNum(tempAmt, this.accMul(rtlPrice, product.quantity));
                }
                this.totalAmt = tempAmt
            },
        },
        methods: {
            privilegeMobile: function () {
                $('#privilege_mobile_input').removeClass('hide')
                $('#privilege_mobile_button').addClass('hide')
                $('#privilege_mobile_input').focus()
            },

            hidden_privilege_mobile_input: function () {
                $('#privilege_mobile_input').addClass('hide')
                $('#privilege_mobile_button').removeClass('hide')
            },

            privilegeAmt: function () {
                $('#privilege_amt_input').removeClass('hidden')
                $('#privilege_amt_button').addClass('hidden')
                $('#privilege_amt_input').focus()
            },
            hidden_privilege_amt_input: function () {
                $('#privilege_amt_input').addClass('hidden')
                $('#privilege_amt_button').removeClass('hidden')
            },
            getProductInfo: _.debounce(
                function () {
                    var vm = this
                    anCode = 1;
                    console.log('barCode：'+this.barCode);
                    var reg = /^\d{8}$|^\d{13}$/
                    if (!reg.test(this.barCode)) {
                        // layer.msg('请正确输入条码')
                        return
                    }
                    layer.load();
                    $.ajax({
                        url: context_Path + '/supermarket/httpPost',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            url: getProductByBC,
                            stringMap: {
                                barCode: vm.barCode,
                                shopId: vm.user.shopId
                            }
                        },
                        success: function (data) {
                            anCode = 1;
                            layer.closeAll('loading')
                            $("#barCodeInput").val('');
                            ////console.log(data)
                            if (data.code != '000') {
                                layer.msg(data.exception)
                                return
                            }

                            var arrayData = data.data;

                            var quantity = arrayData.quantity;
                            var quan = quantity == null ? 1 : quantity;
                            ////console.log(prod)
                            var barCode = arrayData.barCode;

                            if (barCode) {
                                for (ind in vm.productList) {
                                    var prod = vm.productList[ind]
                                    // //console.log(prod)
                                    if (prod.barCode == barCode) {
                                        //console.log('==========>'+prod.quantity +'   '+ quan)
                                        quan = parseInt(prod.quantity) + parseInt(quan);
                                        vm.productList.splice(ind, 1)
                                        break;
                                    }
                                }
                            }
                            // var dispatchPrice = arrayData.dispatchPrice == null ? 0 : arrayData.dispatchPrice;
                            // var rtlPrice = arrayData.rtlPrice;
                            // var arrayRtlPrice = []
                            // if (!dispatchPrice) {
                            //     for(var i = 0; i < 2; i++){
                            //         var array = {}
                            //         if(i == 0){
                            //             array.rtlPrice = rtlPrice;
                            //         }else {
                            //             array.rtlPrice = dispatchPrice;
                            //         }
                            //         //console.log(array)
                            //         arrayRtlPrice.push(array);
                            //     }
                            // }
                            // arrayData.rtlPrice = arrayRtlPrice;
                            arrayData.quantity = quan
                            console.log('商品信息')
                            console.log(arrayData)
                            arrayData.rtlPrices = arrayData.rtlPrice;

                            vm.productList.splice(0, 0, arrayData);
                            //console.log(vm.productList)
                            vm.barCode = ''
                        },
                        error: function (error) {
                            anCode = 1;
                            $("#barCodeInput").val('');
                            layer.closeAll('loading')
                            layer.msg('网络错误')
                        }
                    })

                },
                // 这是我们为用户停止输入等待的毫秒数
                500
            ),
            deleteProduct: function (index) {
                this.productList.splice(index, 1);
            },
            addUnknowProduct: function () {
                anCode = 1;
                var product = {prodName: '未知商品', quantity: '1',priceType: '-', rtlPrice: '1',rtlPrices: '1'}
                this.productList.splice(0, 0, product);
            },
            changeQuantity: function (index, shopType) {
                anCode = 1;
                ////console.log(index)
                $div = $("#product_quantity_" + index) //数量输入的div
                var product = this.productList[index]
                ////console.log(product)
                var reg = /^[1-9][0-9]*$/
                if (!reg.test($div.html())) {
                    layer.msg('输入有误，请重新输入')
                    $div.html(product.quantity)
                    return
                }
                product.quantity = $div.html();
                //console.log(product);
                var tempList = this.productList
                tempList[index] = product
                this.productList = []
                this.productList = tempList
            },
            changePrice: function (index) {
                $div = $("#product_price_" + index) //单价输入的div
                var product = this.productList[index]
                var reg = /^(([1-9]+\.[0-9]{1,2})|(0\.[0-9]{1,2})|([1-9][0-9]*))$/
                if (!reg.test($div.html())) {
                    layer.msg('输入有误，请重新输入')
                    $div.html(product.rtlPrice)
                    return
                }
                product.rtlPrice = $div.html()
                var tempList = this.productList
                tempList[index] = product
                this.productList = []
                this.productList = tempList
            },
            showProdImageFn: function (index) {
                var prod = this.productList[index]
                if (prod.imageUrl) {
                    this.showProdImage = image_prefix + prod.imageUrl
                    $('#prodImage').removeClass('hidden')
                    $('#showImageModel').modal('show')
                } else {
                    layer.msg('没有图片')
                }

            },
            payWayInArray: function (index) {
                if (this.gatheringWay.length == 0) {
                    return true;
                }
                for (idx in this.gatheringWay) {
                    var way = this.gatheringWay[idx];
                    if (way.payMethod == index && way.status == 1) {
                        return true
                        break;
                    }
                }
                return false
            },
            cancelPayOrder: function () {
                var vm = this;
                var index = layer.confirm('确定要放弃本次支付吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    console.log('确定放弃本次支付');
                    anCode = 1;
                    $("#changeM").val('');
                    $("#change").html(0);
                    layer.close(index)
                    anCodeYz = false;
                    confirmOrderYz = true;
                    vm.payType = false;
                    vm.anType = true;
                    $('#payModal').modal('hide')
                    $('#barCodeInput').focus();
                }, function () {
                    console.log('取消放弃本次支付');
                    vm.anType = true;
                    vm.payType = false;
                    anCodeYz = false;
                    confirmOrderYz = true;
                });
            },
            showPayModal: function () {
                layer.load()
                var vm = this;
                if (vm.payType){
                    layer.closeAll('loading')
                    console.log('防止重复调用')
                    return;
                }
                vm.payType = true;
                $.ajax({
                    url: context_Path + '/supermarket/httpPost',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        url: getShopGatheringWay,
                        stringMap: {
                            shopId: this.user.shopId
                        }
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        anCodeYz = true;
                        confirmOrderYz = false;
                        //////console.log(data)
                        if (data.code != '000') {
                            //layer.msg(data.msg)
                            var index = layer.confirm(data.msg, {
                                btn: ['再次获取', '取消'] //按钮
                            }, function () {
                                vm.anType = true;
                                vife = true;

                                layer.close(index)
                                vm.showPayModal();
                            }, function () {
                                vm.anType = true;
                                vife = true;
                            });
                            return
                        }
                        //console.log(data.data)
                        if (shopType != '直营'){
                            vm.gatheringWay = data.data;
                        }
                        // vm.gatheringWay = data.data
                        $("#changeM").focus();
                        anCodeYz = true;
                        $('#payModal').modal('show')
                    }
                    ,
                    error: function (error) {
                        layer.closeAll('loading')
                        //layer.msg('网络错误')
                        var index = layer.confirm('获取收款方式失败（网络错误）', {
                            btn: ['再次获取', '取消'] //按钮
                        }, function () {
                            vife = true;
                            vm.anType = true;
                            layer.close(index)
                            vm.showPayModal();
                        }, function () {
                            vm.anType = true;
                            vife = true;
                        });
                    }
                })

            },
            confirmOrder: function () {
                var vm = this
                anCode = 1;
                var totalAmt = 0;
                if (vm.accSub(this.totalAmt, this.befAmt) <= 0) {
                    layer.msg('订单金额无效')
                    $('#barCodeInput').focus()
                    anCode = 1;
                    vife = true;
                    return;
                }
                //
                // if (Number(this.befAmt) < 0){
                //     layer.msg('订单优惠金额无效')
                //     $('#barCodeInput').focus()
                //     anCode = 1;
                //     vife = true;
                //     return;
                // }

                layer.load();
                var prodList = []
                for (index in vm.productList) {
                    var prod = vm.productList[index]
                    //console.log('店铺类型：'+shopType);
                    if (shopType == '直营' || shopType == '加盟') {
                        //console.log('数量：'+prod.quantity+'      库存：'+prod.stock);
                        if (parseInt(prod.quantity) > parseInt(prod.stock) || parseInt(prod.stock) <= 0) {
                            anCode = 1;
                            $('#barCodeInput').focus()
                            layer.msg("提示：库存不足，不能销售！");
                            layer.closeAll('loading')
                            return
                        }
                    }

                    totalAmt += prod.quantity * prod.rtlPrices;

                    var newProd = {}
                    newProd.shopId = vm.user.shopId;
                    newProd.price = prod.rtlPrice;
                    newProd.seqId = prod.seqId == null ? "" : prod.seqId;
                    newProd.barCode = prod.barCode == null ? "" : prod.barCode;
                    newProd.quantity = prod.quantity;
                    newProd.stock = prod.stock;
                    prodList.push(newProd)
                }
                //生成订单号
                var formatDate = function (data) {
                    if (data < 10) {
                        data = "0" + data
                    }
                    return data
                }
                var date = new Date();
                var time = date.getFullYear().toString() + formatDate(date.getMonth() + 1).toString() + formatDate(date.getDate()).toString() + formatDate(date.getHours()).toString() + formatDate(date.getMinutes()).toString() + formatDate(date.getSeconds()).toString();
                var orderId = 'XS' + vm.user.userId + time;
                vm.orderId = orderId

                //优惠处理
                console.log('totalPrice总金额:' + totalAmt + '   benefitPrice总优惠金额: '+ totalAmt - vm.accSub(vm.totalAmt, vm.befAmt) +'    amt实际金额: '+vm.accSub(vm.totalAmt, vm.befAmt))
                var stringMap = {
                    userId: vm.user.userId,
                    shopId: vm.user.shopId,
                    customerMobile: vm.mobile,
                    orderId: orderId,
                    totalPrice: totalAmt,  //实际金额
                    benefitPrice: totalAmt - vm.accSub(vm.totalAmt, vm.befAmt),   //优惠金额
                    amt: vm.accSub(vm.totalAmt, vm.befAmt),  //实收金额
                    // batchNo: "XSXSXSXS",
                    prodList: JSON.stringify(prodList),
                    type: '5',
                }

                console.log(stringMap)

                $.ajax({
                    url: context_Path + '/supermarket/httpPost',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        url: confirmOrderUrl,
                        stringMap: stringMap
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        // //console.log('====>'+data)
                        if (data.code != '000') {
                            layer.msg(data.msg)
                            return
                        }
                        //支付环节
                        if (data.data) {
                            var guaGuaJiang = serverPath + data.data + "&shopId=" + vm.user.shopId + "&userId=" + vm.user.userId;
                            vm.generPayQrCode(guaGuaJiang, '#gua_qr_code');
                            $("#guaQrCodeContent").removeClass("hide")
                            layer.open({
                                type: 1,
                                title: '扫码刮奖',
                                closeBtn: 1,
                                area: ['300px', '370px'],
                                skin: 'yourclass',
                                content: $("#guaQrCodeContent"),
                                end: function () {
                                    $("#guaQrCodeContent").addClass("hide")
                                }
                            });
                            $("input").focus();
                        }
                        console.log('生成订单号');
                        vm.showPayModal()
                    }
                    ,
                    error: function (error) {
                        anCode = 1;
                        layer.closeAll('loading')
                        layer.msg('网络错误')
                    }
                })
            },
            choosePayWay: function (index) {
                var i = 100;
                var vm = this
                ////console.log(index);

                this.xuLieHao = (parseInt(this.xuLieHao) + 1).toString()

                if (this.xuLieHao.length == 1) {
                    this.xuLieHao = '00' + this.xuLieHao
                } else if (this.xuLieHao.length == 2) {
                    this.xuLieHao = '0' + this.xuLieHao
                }
                if (index != 7) {
                    payType = index;
                    this.getPayQrCodeFn(index) //剩下的交给这个方法去做吧
                } else { //现金支付
                    var vm = this
                    ind = layer.confirm('收到款请点击_确认_按钮', {
                        title: '确认收款',
                        btn: ['确定(' + i + ')', '取消'], //按钮
                        skin: 'layui-layer-molv',
                        success: function (a, b) {
                            layer.close(ind)
                            // $(".layui-layer-btn0").css("backgroundColor", "#92B8B1");
                            var fn = function () {
                                // layer.title(i+' 秒后，系统将自动退出并关闭。',b);
                                i--;
                                //console.log(anCode + '  ' + i)
                                $(".layui-layer-btn0").text('确定支付(' + i + ')');

                            };
                            interval = setInterval(function () {
                                fn();
                                if (i === 0) {
                                    eCode = '';
                                    anCode = 1;
                                    // $(".layui-layer-btn0").css("backgroundColor", "#019F95");
                                    // $(".layui-layer-btn0").text('提交');
                                    clearInterval(interval);
                                    vm.getPayQrCodeFn(index) //实际上是去请求支付
                                    layer.close(ind)
                                }
                            }, 1000);

                            this.enterConfirm = function(event){
                                if(event.keyCode === 13){
                                    // this.anType = false;
                                    console.log("现金回车收款方法");
                                    clearInterval(interval);
                                    $(".layui-layer-btn0").click();
                                    return false; //阻止系统默认回车事件
                                }
                            };
                            $(document).on('keydown', this.enterConfirm); //监听键盘事件

                            // 点击确定按钮回调事件
                            $(".layui-layer-btn0").on("click",function() {
                                //console.log("现金回车收款");
                            })

                        },
                    }, function () {
                        this.anType = true;
                        anCode = 1;
                        console.log("点击确定现金收款");
                        clearInterval(interval);
                        clearInterval(vm.dingShiQiId);
                        vm.getPayQrCodeFn(index) //实际上是去请求支付
                        layer.close(ind)
                    }, function () {
                        vm.anType = true;
                        vm.payType = false;
                        clearInterval(interval);
                        clearInterval(vm.dingShiQiId);
                        $(".layui-layer-btn0").text('确定');
                    });
                }
            },
            getPayQrCodeFn: function (index) {
                var vm = this;
                console.log('获取二维码 店铺类型：'+shopType +'   '+vm.anType +'     '+index);
                if (vm.anType){
                    console.log('获取二维码 店铺类型：'+shopType +'   '+vm.anType +'     '+index);
                    if (shopType == '直营' && index == 11) {
                        index = 'NATIVE';
                    }
                    if (shopType == '直营' && index == 12) {
                        layer.msg('暂未开放，敬请期待');
                        return
                    }
                    vm.anType = false;

                   var stringMap = {
                        userId: vm.user.userId,
                            shopId: vm.user.shopId,
                            type: index,
                            orderId: vm.orderId + vm.xuLieHao,
                            oriOrderId: vm.orderId,
                            txnAmt: vm.accMul(vm.accSub(vm.totalAmt, vm.befAmt), 100),
                    }

                    console.log(stringMap)
                    layer.load()
                    $.ajax({
                        url: context_Path + '/supermarket/httpPost',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            url: getPayQrCode,
                            stringMap: stringMap
                        },

                        success: function (data) {
                            layer.closeAll('loading')
                            //////console.log(data)
                            if (data.code != '000') {
                                layer.msg(data.msg)
                                return;
                            }
                            ////console.log(index)
                            if (index != 7 ) {
                                var qrCodeUrl = data.data == null ? '' : data.data.qrCode;
                                if (index == 5) {
                                    qrCodeUrl = getunionPayQrCodeUrlPre + 'txnAmt=' + vm.accMul(vm.accSub(vm.totalAmt, vm.befAmt), 100) + '&shopId=' + vm.user.shopId + '&userId=' + vm.user.userId + '&orderId=' + vm.orderId;
                                }
                                //console.log('生成二维码，弹出')
                                //生成二维码，弹出
                                vm.generPayQrCode(qrCodeUrl, '#pay_qr_code');
                                vm.showPayQrCodeModal()
                            } else { //现金支付处理分枝
                                vm.coin();   //积分方法调用
                                anCode = 1;
                                vm.productList = []
                                vm.befAmt = '0'
                                vm.mobile = ''
                                clearInterval(interval);
                                clearInterval(vm.dingShiQiId)
                                layer.close(vm.payQrCodeModalId)
                                layer.close(vm.changeId)
                                $('#payModal').modal('hide')
                                vm.getSalesStatistics();
                                vm.hidden_privilege_mobile_input();
                                vm.hidden_privilege_amt_input();
                                layer.msg('收款成功', {icon: 1})
                                $('#barCodeInput').focus()
                                //console.log('确定或自动收款')
                                $('#changeM').val('');
                                $("#change").html(0);
                            }
                        }
                        ,
                        error: function (error) {
                            vm.anType = true;
                            layer.closeAll('loading')
                            layer.msg('网络错误')
                        }
                    })
                }
            },
            generPayQrCode: function (text, content) {
                $(content + ' canvas').remove();
                $(content).qrcode({
                    render: "canvas", //table方式
                    width: 150, //宽度
                    height: 150, //高度
                    text: text //任意内容
                });
            },
            showPayQrCodeModal: function () {
                var i = 100;
                $("#payQrCodeContent").removeClass("hide")
                //定时获取订单支付状态
                var vm = this
                var title = '扫描二维码支付'
                layer.close(ind)

                if(shopType == '直营' && payType == 11){
                    //定时获取订单支付状态
                    this.dingShiQiId = setInterval(this.getOrderPayStatus, 3000);
                }else {
                    if(payType != 6){
                        app.getOrderPayStatus(); //
                    }

                    // $(".layui-layer-btn0").css("backgroundColor", "#92B8B1");
                    var fn = function () {
                        i--;
                        // console.log(anCode + '  ' + i)
                        $(".layui-layer-btn0").text('确定支付(' + i + ')');
                    };
                    interval = setInterval(function () {
                        fn();
                        if (i === 0) {
                            eCode = '';
                            anCode = 1;
                            // $(".layui-layer-btn0").css("backgroundColor", "#019F95");
                            // $(".layui-layer-btn0").text('提交');
                            clearInterval(interval);
                            vm.getPayQrCodeFn(7) //实际上是去请求支付
                            layer.close(ind)
                        }
                    }, 1000);

                    this.enterConfirm = function (event) {
                        if (event.keyCode === 13) {
                            $(".layui-layer-btn0").click();
                            return false; //阻止系统默认回车事件
                        }
                    };
                    $(document).on('keydown', this.enterConfirm); //监听键盘事件

                    // 点击确定按钮回调事件
                    $(".layui-layer-btn0").on("click", function () {
                        //console.log("二维码回车收款");
                    })
                    vm.anType = true;
                }

                if(payType == 6){
                    title = 'pos支付'
                }
                console.log(title);

                this.payQrCodeModalId = layer.open({
                    type: 1,
                    title: title,
                    closeBtn: 1,
                    area: ['300px', '350px'],
                    skin: 'yourclass',
                    content: $("#payQrCodeContent"),
                    btn:['确定支付','取消'],
                    yes:function(index,layero){
                        console.log('点击确定收款')
                        eCode = '';
                        anCode = 1;
                        if(shopType == '直营'&& payType == 11){
                            layer.msg('提示：必须扫码支付！', {icon: 0})
                            return;
                        }
                        if(payType == 6){
                            app.getOrderPayStatus();
                        }
                        vm.anType = true;
                        clearInterval(interval);
                        clearInterval(vm.dingShiQiId);
                        vm.getPayQrCodeFn(7) //实际上是去请求支付
                        layer.close(ind)
                    },
                    btn2:function(index,layero){
                        vm.anType = true;
                        clearInterval(interval);
                        clearInterval(vm.dingShiQiId);
                        layer.close(this.payQrCodeModalId)
                        layer.close(ind)
                    },
                    end: function () {
                        vm.anType = true;
                        clearInterval(interval);
                        clearInterval(vm.dingShiQiId);
                        $("#payQrCodeContent").addClass("hide")
                    }
                });
            },
            getOrderPayStatus: function () {
                //console.log('去获取订单状态' + this.orderId +"    "+ payType);
                //获取订单状态，如果成功，清空相关内容（基本上就只有商品list和优惠金额）和定时器，二维码modal，支付方式选择Modal，提示用户
                var vm = this
                if(shopType == '直营'  && payType == 11 ){
                    $.ajax({
                        url: context_Path + '/supermarket/httpPost',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            url: queryTrade,
                            stringMap: {
                                // userId: vm.user.userId,
                                // shopId: vm.user.shopId,
                                tranType: 'ImmediatePay',
                                id: vm.orderId + vm.xuLieHao,
                                orderId: vm.orderId,
                                // txnAmt: vm.accMul(vm.accSub(vm.totalAmt, vm.befAmt), 100),
                                // orderId: vm.orderId + vm.xuLieHao
                            }
                        },
                        success: function (data) {
                            // //console.log(data)
                            //console.log(data.data.Status)
                            if (data.data.Status != '03') {
                                ////console.log(data.data.STATUS)
                                layer.closeAll('loading')
                                return
                            }
                            vm.coin();   //积分方法调用
                            clearInterval(interval);
                            clearInterval(vm.dingShiQiId);
                            vm.productList = []
                            vm.befAmt = '0';
                            vm.mobile = ''
                            vm.getSalesStatistics();   //刷新日销量
                            layer.close(vm.payQrCodeModalId)
                            layer.close(vm.changeId)
                            $("#payQrCodeContent").addClass("hide")
                            $('#payModal').modal('hide')
                            layer.msg('支付成功', {icon: 1})
                            $('#barCodeInput').focus()
                            $('#changeM').val('');
                            $("#change").html(0);
                            clearInterval(interval);
                        }
                        ,
                        error: function (error) {
                            clearInterval(interval);
                        }
                    })
                }else if(payType == 6){
                    $.ajax({
                        url: context_Path + '/supermarket/httpPost',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            url: sendPayResult,
                            stringMap: {
                                orderId: vm.orderId + vm.xuLieHao
                            }
                        },
                        success: function (data) {
                            //console.log(data.code)
                            if (!data.success) {
                                return
                            }
                            if (data.data.STATUS != '1') {
                                ////console.log(data.data.STATUS)
                                layer.closeAll('loading')
                                return
                            }
                            return
                            vm.coin();   //积分方法调用
                            clearInterval(interval);
                            clearInterval(vm.dingShiQiId);
                            vm.productList = []
                            vm.befAmt = '0';
                            vm.mobile = ''
                            layer.close(vm.payQrCodeModalId)
                            layer.close(vm.changeId)
                            $("#payQrCodeContent").addClass("hide")
                            $('#payModal').modal('hide')
                            layer.msg('支付成功', {icon: 1})
                            $('#barCodeInput').focus()
                            $('#changeM').val('');
                            $("#change").html(0);

                        }
                        ,
                        error: function (error) {
                            clearInterval(interval);
                        }
                    })
                }else {
                    $.ajax({
                        url: context_Path + '/supermarket/getOrderState',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            orderId: vm.orderId + vm.xuLieHao
                        },
                        success: function (data) {
                            //////console.log(data)
                            if (!data.success) {
                                return
                            }
                            if (data.data.STATUS != '1') {
                                ////console.log(data.data.STATUS)
                                layer.closeAll('loading')
                                return
                            }
                            return
                            vm.coin();   //积分方法调用
                            clearInterval(interval);
                            clearInterval(vm.dingShiQiId);
                            vm.productList = []
                            vm.befAmt = '0';
                            vm.mobile = ''
                            layer.close(vm.payQrCodeModalId)
                            layer.close(vm.changeId)
                            $("#payQrCodeContent").addClass("hide")
                            $('#payModal').modal('hide')
                            layer.msg('支付成功', {icon: 1})
                            $('#barCodeInput').focus()
                            anCodeYz = false;
                            confirmOrderYz = true;
                        }
                        ,
                        error: function (error) {
                            clearInterval(interval);
                        }
                    })
                }
            },
            clearShu: function () {
                layer.close(index)
                vm.showPayModal();
            },
            //乘法
            accMul: function (arg1, arg2) {
                var m = 0, s1 = arg1.toString(),
                    s2 = arg2.toString();
                try {
                    m += s1.split(".")[1].length
                } catch (e) {
                }
                try {
                    m += s2.split(".")[1].length
                } catch (e) {
                }
                return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m
                )
            },
            //自定义加法运算
            addNum: function (num1, num2) {
                var sq1, sq2, m;
                try {
                    sq1 = num1.toString().split(".")[1].length;
                }
                catch (e) {
                    sq1 = 0;
                }
                try {
                    sq2 = num2.toString().split(".")[1].length;
                }
                catch (e) {
                    sq2 = 0;
                }
                m = Math.pow(10, Math.max(sq1, sq2));
                return (num1 * m + num2 * m) / m;
            },
            //减法
            accSub: function (arg1, arg2) {
                var r1, r2, m, n;
                try {
                    r1 = arg1.toString().split(".")[1].length
                } catch (e) {
                    r1 = 0
                }
                try {
                    r2 = arg2.toString().split(".")[1].length
                } catch (e) {
                    r2 = 0
                }
                m = Math.pow(10, Math.max(r1, r2));
                n = (r1 >= r2) ? r1 : r2;
                return ((arg1 * m - arg2 * m) / m).toFixed(n);
            },
            //除法
            accDiv: function (arg1, arg2) {
                var t1 = 0, t2 = 0, r1, r2;
                try {
                    t1 = arg1.toString().split(".")[1].length
                } catch (e) {
                }
                try {
                    t2 = arg2.toString().split(".")[1].length
                } catch (e) {
                }
                with (Math) {
                    r1 = Number(arg1.toString().replace(".", ""))
                    r2 = Number(arg2.toString().replace(".", ""))
                    return (r1 / r2) * pow(10, t2 - t1);
                }
            },
            getSalesStatistics: function () {
                var vm = this
                layer.load()
                $.ajax({
                    url: context_Path + '/supermarket/httpPost',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        url: getSalesStatistics,
                        stringMap: {
                            userId: vm.user.userId,
                            shopId: vm.user.shopId,
                            userType: '003',
                            selectType: 'hh24'
                        }
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        var totalPrices = data.data.totalPrices;
                        app.totalPrices = totalPrices == null ? 0 : totalPrices;

                        vm.anType = true;
                        vm.payType = false;
                        anCodeYz = false;
                        confirmOrderYz = true;
                    }
                    ,
                    error: function (error) {
                        layer.closeAll('loading')
                        layer.msg('网络错误')
                    }
                })
            },
            price: function(index,product){
                var vm = this;
                var rtlPrice = 0;
                console.log('价格的更换'+index+'  '+product)
                if(!product.barCode){
                    return;
                }

                layer.load();
                $.ajax({
                    url: context_Path + '/supermarket/httpPost',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        url: getProductByBC,
                        stringMap: {
                            barCode: product.barCode,
                            shopId: vm.user.shopId
                        }
                    },
                    success: function (data) {
                        anCode = 1;
                        layer.closeAll('loading')
                        if (data.code != '000') {
                            layer.msg(data.exception)
                            return
                        }
                        var product = data.data;
                        console.log(product)

                        if(!product.rtlPrice){
                            $('#price1').addClass('hide');
                        }
                        if(!product.dispatchPrice){
                            $('#price2').addClass('hide');
                        }
                        if(!product.vipPrice){
                            $('#price3').addClass('hide');
                        }
                        $('#optionsRadios1').val(product.rtlPrice)
                        $('#optionsRadios2').val(product.dispatchPrice)
                        $('#optionsRadios3').val(product.vipPrice)
                        $('#rtlPrice').html(product.rtlPrice)
                        $('#dispatchPrice').html(product.dispatchPrice)
                        $('#vipPrice').html(product.vipPrice)
                        rtlPrice = product.rtlPrice;
                    },
                    error: function (error) {
                        anCode = 1;
                        $("#barCodeInput").val('');
                        layer.closeAll('loading')
                        layer.msg('网络错误')
                        return;
                    }
                })

                $("#priceContent").removeClass("hide")
                var priceModalId = layer.open({
                    type: 1,
                    title: '价格类型',
                    closeBtn: 1,
                    area: ['300px', '350px'],
                    skin: 'yourclass',
                    content: $("#priceContent"),
                    btn:['确定','取消'],
                    yes:function(){
                        var product_price_id = '#product_price_'+index;
                        var product_priceType_id = '#product_priceType_'+index;
                        var price = $("input[name='optionsRadios']:checked").val();
                        var id = $("input[name='optionsRadios']:checked").attr('id');

                        console.log(product.quantity);

                        if(id == 'optionsRadios2'){
                            $(product_priceType_id).html('团');
                        }
                        if(id == 'optionsRadios3'){
                            $(product_priceType_id).html('会');
                        }

                        // $(product_price_id).html(price);

                        app.changePrice(index)
                        product.rtlPrice = price;

                        // this.productList.splice(0, 0, product);
                        layer.close(priceModalId)
                    },
                    btn2:function(){
                        this.anType = true;
                        this.payType = false;
                        //console.log('取消')
                        layer.close(priceModalId)
                    },
                    end: function () {
                        $("#priceContent").addClass("hide")
                        layer.close(priceModalId)
                    }
                });
            },
            //积分
            // coinIntegral: function () {
            //     layer.load();
            //     var vm = this;
            //     $.ajax({
            //         url: context_Path + '/supermarket/httpPost',
            //         type: 'post',
            //         dataType: 'json',
            //         data: {
            //             url: coinIntegral,
            //             stringMap: {
            //                 coinType: '3',
            //                 amt: vm.accSub(vm.totalAmt, vm.befAmt),
            //                 type: '',
            //                 url: 'PC扫码'
            //             }
            //         },
            //         success: function (data) {
            //             layer.closeAll('loading')
            //             if (data.code != '000') {
            //                 layer.msg(data.exception)
            //                 return
            //             }
            //
            //         },
            //         error: function (error) {
            //             anCode = 1;
            //             $("#barCodeInput").val('');
            //             layer.closeAll('loading')
            //             layer.msg('网络错误')
            //             return;
            //         }
            //     })
            //
            // }
            //积分操作
            coin: function () {
                var vm = this;
                var stringMap = {
                    userId: vm.user.userId,
                    shopId: vm.user.shopId,
                    mobile: vm.mobile,
                    type: index,
                    orderId: vm.orderId + vm.xuLieHao,
                    oriOrderId: vm.orderId,
                    txnAmt: vm.accMul(vm.accSub(vm.totalAmt, vm.befAmt), 100),
                }
                console.log(stringMap)
                $.ajax({
                    url: context_Path + '/supermarket/httpPost',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        url: getPayQrCode,
                        stringMap: stringMap
                    },

                    success: function (data) {
                        console.log('增加积分：会卡：'+ stringMap.mobile+'    积分：'+stringMap.txnAmt)
                    }
                });
            }

        }
    })
;